/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import business.HotelsBusiness;
import business.LocationsBusiness;
import business.PlacesBusiness;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;
import model.Hotels;
import model.Locations;
import model.Places;

/**
 *
 * @author Administrator
 */
@ManagedBean
@SessionScoped
public class testMenuBean {

    private LocationsBusiness locationsBusiness = new LocationsBusiness();
    private PlacesBusiness placesBusiness = new PlacesBusiness();
    private HotelsBusiness hotelsBusiness = new HotelsBusiness();
    private int localID;
    private int placeID;
    private List<Locations> listLocal;
    private List<Places> listPlace;
    private List<Hotels> listHotel;
    private Date dateFrom;

    public Date getDateFrom() {
        return dateFrom;
    }

    public void setDateFrom(Date dateFrom) {
        this.dateFrom = dateFrom;
    }

    private String formatDateFrom(Date dateFrom) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
        String dateFromString = formatter.format(dateFrom);
        return dateFromString;
    }

    public List<Hotels> getListHotel() {
        return listHotel;
    }

    public void setListHotel(List<Hotels> listHotel) {
        this.listHotel = listHotel;
    }

    public List<Locations> getListLocal() {
        return listLocal;
    }

    public void setListLocal(List<Locations> listLocal) {
        this.listLocal = listLocal;
    }

    public List<Places> getListPlace() {
        return listPlace;
    }

    public void setListPlace(List<Places> listPlace) {
        this.listPlace = listPlace;
    }

    public int getLocalID() {
        return localID;
    }

    public void setLocalID(int localID) {
        this.localID = localID;
    }

    public int getPlaceID() {
        return placeID;
    }

    public void setPlaceID(int placeID) {
        this.placeID = placeID;
    }

    public void placeChangeByID(ValueChangeEvent e) {
        localID = Integer.parseInt(e.getNewValue().toString());
        listPlace = placesBusiness.listPlacesByLocalID(localID);

        int pID = listPlace.get(0).getPlaceID();
        newPlaceId = pID;
        flagPlace = true;
        listHotel = hotelsBusiness.listHotelByPlaceID(pID);
    }
    boolean flagPlace = false;
    int newPlaceId = 1;

    public void hotelChangeByPlaceID(ValueChangeEvent ex) {
        if (flagPlace) {
            placeID = newPlaceId;
            flagPlace = false;
        } else {
            placeID = Integer.parseInt(ex.getNewValue().toString());
        }

        listHotel = hotelsBusiness.listHotelByPlaceID(placeID);

    }

    /** Creates a new instance of testMenuBean */
    public testMenuBean() {
        localID = 1;
        placeID = 1;
        listLocal = locationsBusiness.listAllLocation();
        listPlace = placesBusiness.listPlacesByLocalID(localID);
        listHotel = hotelsBusiness.listHotelByPlaceID(placeID);
    }
}
